<template>
  <div class="social-signup-container">
    <div>
        <span>默认</span>
        <el-image :src="picUrl" ></el-image>
        <!-- <y-image :picUrl="picUrl"></y-image> -->
        <!-- <img src="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQEp7zwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAydjlSYVZDcHRjbkgxNFJ2VDF3Y1IAAgRNWzdgAwToAwAA"/> -->
        <el-button type="primary" size="mini" @click="submit">获取二维码</el-button>
      </div>
    <div class="sign-btn" @click="wechatHandleClick('wechat')">
      <span class="wx-svg-container"><svg-icon icon-class="wechat" class="icon" /></span>
      WeChat
    </div>
    <div class="sign-btn" @click="tencentHandleClick('tencent')">
      <span class="qq-svg-container"><svg-icon icon-class="qq" class="icon" /></span>
      QQ
    </div>
  </div>
</template>

<script>
// import openWindow from '@/utils/open-window'

export default {
  name: 'SocialSignin',
  methods: {
    submit() {
          qrCodeCreateTmpTicket().then(response => {
            if (response.code === '000000') {
              // this.$alert(response.data.temporaryQR)
              this.picUrl=response.data.temporaryQR
              this.sceneStr=response.data.sceneStr
              window.timer=setInterval(()=>{
  setTimeout(this.getBySceneStr(),0)
},5000)
              // clearInterval(timer)
              // this.msgSuccess(response.mesg)
            } else if (response.code === '050000') {
              this.msgWarning(response.mesg)
            }
          })
    },
    getBySceneStr(){

       getSceneStr(this.sceneStr).then(response => {
            if (response.code === '000000') {
              if(response.mesg!='no'){
                this.loginForm.username=response.mesg
                this.loginForm.password=this.sceneStr
                clearInterval(timer)
                this.loginForm.grant_type="officialaccount"
           this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
              this.loading = false
              this.loginForm.grant_type="custom"
            })
            .catch(() => {
              this.loading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
              }
            } else if (response.code === '050000') {
              this.msgWarning(response.mesg)
            }
          })
    },
    wechatHandleClick(thirdpart) {
      alert('ok')
      // this.$store.commit('SET_AUTH_TYPE', thirdpart)
      // const appid = 'xxxxx'
      // const redirect_uri = encodeURIComponent('xxx/redirect?redirect=' + window.location.origin + '/auth-redirect')
      // const url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&response_type=code&scope=snsapi_login#wechat_redirect'
      // openWindow(url, thirdpart, 540, 540)
    },
    tencentHandleClick(thirdpart) {
      alert('ok')
      // this.$store.commit('SET_AUTH_TYPE', thirdpart)
      // const client_id = 'xxxxx'
      // const redirect_uri = encodeURIComponent('xxx/redirect?redirect=' + window.location.origin + '/auth-redirect')
      // const url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=' + client_id + '&redirect_uri=' + redirect_uri
      // openWindow(url, thirdpart, 540, 540)
    }
  }
}
</script>

<style lang="scss" scoped>
  .social-signup-container {
    margin: 20px 0;
    .sign-btn {
      display: inline-block;
      cursor: pointer;
    }
    .icon {
      color: #fff;
      font-size: 24px;
      margin-top: 8px;
    }
    .wx-svg-container,
    .qq-svg-container {
      display: inline-block;
      width: 40px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      padding-top: 1px;
      border-radius: 4px;
      margin-bottom: 20px;
      margin-right: 5px;
    }
    .wx-svg-container {
      background-color: #24da70;
    }
    .qq-svg-container {
      background-color: #6BA2D6;
      margin-left: 50px;
    }
  }
</style>
